<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>图书展示</title>
</head>
<script src="/js/jquery-3.7.0.js"></script>
<script th:inline="javascript">
    let page=[[${page}]]
    if (page==null){
        location.href='http://localhost:8080/getPage'
    }
    $(function (){
        let name=[[${name}]]
        let price=[[${price}]]

        if (name!=null && name!=''){
            $("#name").val(name);
        }
        if (price!=null && price!=''){
            $("#price").val(price);
        }
    })
</script>
<body>
   <form method="post" th:action="@{/getPage}">
       图书名称:<input id="name" type="text" name="name">
       图书价格:<input id="price" type="text" name="price">
       <input type="submit" value="查询">
   </form>
   <form method="post" th:action="@{/delMany}">
   <table border="1" >
       <tr>
           <td>选择</td>
           <td>编号</td>
           <td>书名</td>
           <td>价格</td>
           <td>类目</td>
           <td>库存</td>
           <td>图片</td>
           <td>说明</td>
           <td>作者</td>
           <td>已售</td>

       </tr>

       <tr th:each="book:${page.list}">
           <td><input name="ids" type="checkbox" th:value="${book.id}"></td>
           <td th:text="${book.id}"></td>
           <td th:text="${book.name}"></td>
           <td th:text="${book.price}"></td>
           <td th:text="${book.category}"></td>
           <td th:text="${book.pnum}"></td>
           <td th:text="${book.imgurl}"></td>
           <td th:text="${book.description}"></td>
           <td th:text="${book.author}"></td>
           <td th:text="${book.sales}"></td>
       </tr>
   </table>
       <input type="submit" value="批量删除">
   </form>

总页数 ：<span th:text="${page.pages}"></span>
总记录数 ：<span th:text="${page.total}"></span>
当前页码 ：<span th:text="${page.pageNum}"></span>
   <br/>
<span th:if="${page.hasPreviousPage}">
    <a th:href="@{/getPage(pageNum=${page.pageNum -1},name=${name},price=${price})}">上一页</a>
</span>
   <span th:each="num,status:${#numbers.sequence(1,page.pages)}">
       <a th:href="@{/getPage(pageNum=${status.count},name=${name},price=${price})}" th:text="${status.count}"></a>
   </span>
   <span th:if="${page.nextPage}">
    <a th:href="@{/getPage(pageNum=${page.pageNum +1},name=${name},price=${price})}">下一页</a>
</span>
<button onclick="goAdd()">
    新增图书
</button>
<script>
    function goAdd(){
        location.href='http://localhost:8080/add'
    }
</script>
</body>

</html>